﻿#ifndef BaiduFaceOnline_H
#define BaiduFaceOnline_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include <QUrlQuery>
#include <QNetworkReply>
#include <QMessageBox>
#include <QImage>
#include <QFile>
#include <QTextStream>
#include <QBuffer>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTimer>

#define id_card_fside 0
#define id_card_bside 1

class BaiduFaceOnline : public QObject
{
    Q_OBJECT
public:
    explicit BaiduFaceOnline(QObject *parent = nullptr);

    void https_ssl_config(QNetworkRequest& NetworkRequest);
    QString image2base64_str(const QImage& img);
    QImage base64_str2image(const QString & base64_str);

public slots:
    void getAccToken(const QString& API_Key, const QString& Secret_Key); //获取鉴权码
    void Faceverify(const QImage& image);
    void FaceDetect(const QImage& image);
    void FaceMatch(const QImage& image1, const QImage& image2);
    void FaceSerch(const QImage& image);
    void FaceRegister(const QImage& image, const QString& group_id, const QString& user_id);

private slots:
    void getAccTokenReply(QNetworkReply* reply);
    void FaceverifyReply(QNetworkReply* reply);
    void FaceDetectReply(QNetworkReply* reply);
    void FaceMatchReply(QNetworkReply* reply);
    void FaceSerchReply(QNetworkReply* reply);
    void FaceRegisterReply(QNetworkReply* reply);

signals:
    void FaceverifyResult(const QString& result);
    void DetectResult(const QString&  content);
    void MatchResult(const QString&  content);
    void SerchResult(const QString&  content);
    void RegisterResult(const QString&  content);

private:
    QNetworkAccessManager* NetAccManager;
    QNetworkRequest NetRequest;
    QUrlQuery QueryItem;
    /* 应用参数 */
    QString AccToken = "";
    /* 应用参数end */
    const QString AccTokenUrl = "https://aip.baidubce.com/oauth/2.0/token";
    const QString FaceverifyUrl = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify";
    const QString FaceMatchUrl = "https://aip.baidubce.com/rest/2.0/face/v3/match";
    const QString FaceSerchUrl = "https://aip.baidubce.com/rest/2.0/face/v3/search";
    const QString FaceDetectUrl = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
    const QString FaceAddUrl = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add";

};

#endif // BAIDUFACEONLINE_H
